
$("#outerdiv").hide();
$(function(){
    $("img").mouseover(function(){
        $(this).css("cursor","pointer");
    });

    $("img").click(function(){
        var _this = $(this);//将当前的pimg元素作为_this传入函数
        imgShow("#outerdiv", "#bigimg", _this);
    });
});

function imgShow(outerdiv, bigimg, _this) {
    var src = _this.attr("src");//获取当前点击的pimg元素中的src属性
    $('#outerdiv').attr('display', 'block');
    $(bigimg).attr("src", src);//设置#bigimg元素的src属性
    $(outerdiv).fadeIn("fast");

    $(outerdiv).click(function () {//再次点击淡出消失弹出层
        $(this).fadeOut("fast");
    });
}


var path=window.location.href;

    // history.pushState(null, null, document.URL);
    // window.addEventListener('popstate', function () {
    //     history.pushState(null, null, document.URL);
    //     window.opener=null;
    //     window.open('','_self');
    //     window.close();
    // })
    // $("#headpage").hide();//表示display:block,
    window.addEventListener("popstate", function(e) {
        //alert("我监听到了浏览器的返回按钮事件啦");//根据自己的需求实现自己的功能
        //alert('guanbi');
        if(path.indexOf("/view/adlist.html")>0)
        {
            window.opener = null;
            window.open('', '_self', '');
            window.close();
        }
        if(path.indexOf("/view/free.html")>0)
        {
            window.opener = null;
            window.open('', '_self', '');
            window.close();
        }
    }, false);
// }
// else {
//
//     $("#headpage").show();//表示display:none;
// }

if (path.indexOf("view/addetails.html")>0)
{

}
else {
    function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    }

    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
}


function  imgsrcpath() {
    return "http://qb.kmhkj.top:8008";
}


var phone=/^1[34578]\d{9}$/;
function Isphone(tjPhone) {
    if(tjPhone.match(phone)==null){

        return false;
    }
    else {
        return true;
    }
}
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}


function add0(m){return m<10?'0'+m:m }
function formattime(timestamp)
{
    //timestamp是整数，否则要parseInt转换,不会出现少个0的情况
    var time = new Date(timestamp);
    var year = time.getFullYear();
    var month = time.getMonth()+1;
    var date = time.getDate();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var seconds = time.getSeconds();

    return year+'-'+add0(month)+'-'+add0(date)+' '+add0(hours)+':'+add0(minutes)+':'+add0(seconds);
}

function formattimeuser(timestamp)
{
    return new Date(parseInt(timestamp) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');

}
 //状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级

function  getstatustype(obj) {
    if (obj==0) {
        return  "待付款";
    }
    if (obj==1) {
        return  "待确认";
    }
    if (obj==2) {
        return  "待完成";
    }
    if (obj==3) {
        return "待支付尾款";
    }
    if (obj==4) {
        return  "待审核";
    }
    if (obj==5) {
        return   "已完成";
    }
    if (obj==6) {
        return  "已升级";}
    if (obj==7) {
        return  "审核不通过";
    }
}
//免费区域订单使用
function  getstatustypefree(obj) {
    if (obj==0) {
        return  "待付款";
    }
    if (obj==1) {
        return  "待确认";
    }
    if (obj==2) {
        return  "待完成";
    }
    if (obj==3) {
        return "待支付尾款";
    }
    if (obj==4) {
        return  "检测中";
    }
    if (obj==5) {
        return   "已检测";
    }
    if (obj==6) {
        return  "已升级";}
    if (obj==7) {
        return  "已检测";
    }
}

//类型:0=测斑,1=局部,2=升级,3=全套,4=售后,5=代理,6协助
function  gettypedata(obj) {
    if (obj==0) {return "免费测斑";}
    if (obj==1) {return "局部体验";}
    if (obj==2) {return "订单升级";}
    if (obj==3) {return "签约祛斑";}
    if (obj==4) {return "售后";}
    if (obj==5) {return "代理申请";}
    if (obj==6) {return "协助";}
}

//等级类型:0=粉丝,1=客户,2=一级经纪人,3=代理商,4=后续经纪人',
function  getusertypedata(obj) {
    if (obj==0) {return "粉丝";}//0
    if (obj==1) {return "客户";}//1
    if (obj==2) {return "一级经纪人";}//2
    if (obj==3) {return "加盟商";}//4
    if (obj==4) {return "后续经纪人";}//3

}

function  getusertypedatateam(obj) {
    if (obj==0) {return "粉丝";}//0
    if (obj==1) {return "客户";}//1
    if (obj==2) {return "一级经纪人";}//2
    if (obj==3) {return "代理";}//4
    if (obj==4) {return "后续经纪人";}//3

}
//物料类型
function  getwuliaotype(obj) {
    if (obj==0) {return "局部";}
    if (obj==1) {return "全套";}
}

//佣金类型状态:0=客单,1=协助,2=押金，3=提现 4=红利
function  gettixiatype(obj) {
    if (obj==0) {return "佣金";}
    if (obj==1) {return "协助";}
    if (obj==2) {return "押金";}
    if (obj==3) {return "提现";}
    if (obj==4) {return "红利";}
}

//佣金类型状态:0=未申请,1=待付款,2=已付款,3=已处理不显示
function  gettixiastatus(obj) {
    if (obj==0) {return "未申请";}
    if (obj==1) {return "待付款";}
    if (obj==2) {return "已付款";}
    if (obj==3) {return "已处理不显示";}
}
//订单号，状态，
function  admintixiabtn(obj,obj2) {
        return '<a  class="mui-btn mui-btn-primary"  href="settixianmixi.html?id='+obj+'&status='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看明细</a>';
}

function  wxfenxbtn(obj) {
    return '<a  href="fenxaddetails.html?id='+obj+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right">分享</a>';

}

//广告管理按钮
function  adminadbtn(obj) {
    return '<a  href="adminadedit.html?id='+obj+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right;font-size: 12px;">修改</a>'
        +'<a  href="JavaScript:deletead('+obj+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;background-color: #FF8C69; font-size: 12px;border: 1px solid #FF8C69;float:right;margin-right: 4px;" >完全删除</a>'
  +  '<a  href="adminaduserall.html?id='+obj+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right;font-size: 12px;margin-right: 4px;">查看浏览人员</a>'
    +'<a  href="JavaScript:findwx('+obj+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right;font-size: 12px;margin-right: 4px;">推送</a>'
}
//状态:0=未发货,1=已发货
function  getwuliaostatus(obj) {
    if (obj==0) {return "未发货";}
    if (obj==1) {return "已发货";}
}
//类型:0=测斑,1=局部,2=升级,3=全套,4=售后,5=代理
//状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级
//数据状态，数据id，数据类型
function  getbutten(obj,obj2,obj3,isonce) {
    if (obj==0&&obj3==1) {
        return '<a  href="JavaScript:getwxkey('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >去付款</a>'
    }
    if (obj==5&&obj3==5) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF; ">查看详情</a>'
    }
    if (obj==4&&obj3==5) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF; ">查看详情</a>'
    }
    if (obj==0&&obj3==5) {
        return '<a  href="JavaScript:getwxkey('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >去付款</a>'
    }

    if (obj==4&&obj3==1) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF; ">查看详情</a>'
    }
    if (obj==2&&obj3==1) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF; ">查看详情</a>'
    }
    if (obj==5&&obj3==1) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF; ">查看详情</a>'
    }

    if (obj==1&&obj3==1) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right">查看详情</a>'
            +'<a  href="JavaScript:getwxkeyordeup('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;background-color: #FF8C69; border: 1px solid #FF8C69;float:right;margin-right: 4px;" >订单升级</a>'
    }
    if (obj==5&&obj3==3&&!isonce) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right" >查看详情</a>'
            +'<a  href="JavaScript:insertFullnew('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;background-color: #FF8C69; border: 1px solid #FF8C69;float:right;margin-right: 4px;" >再次服务</a>'
    }
    if (obj==5&&obj3==3&&isonce) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >查看详情</a>'
    }
    if (obj==0&&obj3==3) {
        return '<a  href="JavaScript:getwxkey('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >去付款</a>'
    }
    if (obj==3&&obj3==3) {
        return '<a  href="JavaScript:getwxkey('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >支付尾款</a>'
    }
    if (obj==1&&obj3==3) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >查看详情</a>'
    }
    if (obj==4&&obj3==3) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >查看详情</a>'
    }
    if (obj==2&&obj3==3) {
        return '<a  href="useroreddetails.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF; ">查看详情</a>'
    }

}


//物料类型
function  getinassitanttype(obj) {
    if (obj==null||obj==undefined||obj=="") {return "待指派";}
    else {
        return "已指派";
    }

}

//协助订单按钮
function admininassitantbtn(obj,obj2) {
    if (obj2==null||obj2==undefined||obj2=="") {
        return '<a  class="mui-btn mui-btn-primary" href="adminuser.html?ordeid='+obj+'" style="height: 30px;margin-top: 5px;color: #FFF;">指派经纪人</a>';
    }
    else {
        return '<a  class="mui-btn mui-btn-primary" href="adminassitantdetail.html?id='+obj+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
}


//订单类型，订单状态,订单号，订单状态
function  adminbutten(obj,obj2,obj3,isassitant,userid) {

    if (obj==0&&obj3==4) {
        return '<a  class="mui-btn mui-btn-primary" href="adminfreedetail.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">通过审核</a>';
    }
    if (obj==0&&obj3==5) {
        return '<a  class="mui-btn mui-btn-primary" href="adminfreedetail.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
    if (obj==0&&obj3==7)
    {
        return '<a  class="mui-btn mui-btn-primary" href="adminfreedetail.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }

    if (obj==1&&obj3==4) {
        return '<a  class="mui-btn mui-btn-primary" href="adminuseroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">通过审核</a>';
    }
    if (obj==1&&(obj3<4||obj3==5)) {
        return '<a  class="mui-btn mui-btn-primary" href="adminuseroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }

    if (obj==3&&obj3==4) {
        return '<a  class="mui-btn mui-btn-primary" href="adminuseroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">通过审核</a>';
    }
    if (obj==3&&(obj3<4||obj3==5)) {
        return '<a  class="mui-btn mui-btn-primary" href="adminuseroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }

    if (obj==5&&obj3==4) {
        return '<a  class="mui-btn mui-btn-primary" href="adminagentdetail.html?id='+obj2+'&userid='+userid+'" style="height: 30px;margin-top: 5px;color: #FFF;">通过审核</a>';
    }
    if (obj==5&&obj3==5) {
        return '<a  class="mui-btn mui-btn-primary" href="adminagentdetail.html?id='+obj2+'&userid='+userid+'"  style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
    if (obj==5&&(obj3<4||obj3==5)) {
        return '<a  class="mui-btn mui-btn-primary" href="adminagentdetail.html?id=' + obj2 + '&userid=' + userid + '"  style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
}

//订单号，用户id，用户姓名
function  adminuserbtn(obj,obj2,obj3) {
        return '<a  class="mui-btn mui-btn-primary"  href="JavaScript:saveordeuser('+obj+'\,\''+obj2+'\',\''+obj3+'\');" style="height: 30px;margin-top: 5px;color: #FFF;">指派该经纪人</a>';
}

//用户id
function  adminalluserbtn(obj) {
    return '<a  class="mui-btn mui-btn-primary"  href="JavaScript:saveordeuser('+obj+');" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
}

//需要修改的用户id
function  adminupdataUpagent(obj) {
    return '<a  class="mui-btn mui-btn-primary"  href="JavaScript:saveordeuser('+obj+');" style="height: 30px;margin-top: 5px;color: #FFF;">修改为该经纪人</a>';
}

//物料页面按钮
//订单号，发货状态，用户id
function  adminwuliaobtn(obj,obj2,obj3) {
    if (obj2==0) {
        return '<a  class="mui-btn mui-btn-primary"  href="JavaScript:wuliaoupdate('+obj+','+obj2+','+obj3+');" style="height: 30px;margin-top: 5px;color: #FFF;">确认发货</a>';
    }
    else {
        return "";
    }

}
//经纪人协助页面按钮
//    //状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级
// 订单类型，订单号，订单状态，是否协助
function  getagentassitantbtn(obj,obj2,obj3) {
    var  materielA=getCookie('materielA');
    var  materielB=getCookie('materielB');
    if (materielA==0||materielB ==0)
    {
        return "物料不足无法查看";
    }
    //全套
    if (obj==3&&obj3==2) {
        return '<a  class="mui-btn mui-btn-primary" href="agentokorde.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">去完成</a>';
    }
    if (obj==3&&obj3==4) {
        return '<a  class="mui-btn mui-btn-primary" href="useroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }

    if (obj==3&&obj3==5) {
        return '<a  class="mui-btn mui-btn-primary" href="useroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
    if (obj==3&&obj3==1) {
        return '<a   href="agentqianyuok.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >去确认</a>';
    }
    //局部
    if (obj==1&&obj3==2) {
        return '<a  class="mui-btn mui-btn-primary" href="agentokorde.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">去完成</a>';
    }
    if (obj==1&&obj3==4) {
        return '<a  class="mui-btn mui-btn-primary" href="useroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }

    if (obj==1&&obj3==5) {
        return '<a  class="mui-btn mui-btn-primary" href="useroreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
    if (obj==1&&obj3==1) {
        return '<a  href="JavaScript:jubuok('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;" >去确认</a>';


    }
}
//经纪人局部签约按钮
//    //状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级
// 订单类型，订单号，订单状态，是否协助
function  getagentbutten(obj,obj2,obj3,isassitant) {
    var  materielA=getCookie('materielA');
    var  materielB=getCookie('materielB');

    if (materielA==0||materielB ==0)
    {
        return "物料不足无法查看";
    }
    //签约状态3，无协助，待完成
    if (obj==3&&obj3==2&&!isassitant) {
        return '<a  class="mui-btn mui-btn-primary" href="agentokorde.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">去完成</a>';
    }
    //签约状态3，有协助，待完成
    if (obj==3&&obj3==2&&isassitant) {
        return '<a  class="mui-btn mui-btn-primary" href="agentoreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }

    //签约状态3，无协助，待确认
    if (obj==3&&!isassitant&&obj3==1) {
        return '<a   href="agentqianyuok.html?id='+obj2+'" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right" >去确认</a>'
            +'<a  href="JavaScript:updateOrderisassitant('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;background-color: #FF8C69; border: 1px solid #FF8C69;float:right;margin-right: 4px;" >申请协助</a>'
    }
    //签约状态3，有协助，待确认
    if (obj==3&&isassitant&&obj3==1) {
        return '<a  class="mui-btn mui-btn-primary" href="agentoreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }


    //局部状态1，无协助，待完成
      if (obj==1&&obj3==2&&!isassitant) {
        return '<a  class="mui-btn mui-btn-primary" href="agentokorde.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">去完成</a>';
    }
    //局部状态1，有协助，待完成
    if (obj==1&&obj3==2&&isassitant) {
        return '<a  class="mui-btn mui-btn-primary" href="agentoreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
    //局部状态1，无协助，待确认
    if (obj==1&&!isassitant&&obj3==1) {
        return '<a  href="JavaScript:jubuok('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;float: right" >去确认</a>'
            +'<a  href="JavaScript:updateOrderisassitant('+obj2+');" class="mui-btn mui-btn-primary" style="height: 30px;margin-top: 5px;color: #FFF;background-color: #FF8C69; border: 1px solid #FF8C69;float:right;margin-right: 4px;" >申请协助</a>'
    }

    //局部状态1，有协助，待确认
    if (obj==1&&isassitant&&obj3==1) {
        return '<a  class="mui-btn mui-btn-primary" href="agentoreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';
    }
//改到这里


        return '<a  class="mui-btn mui-btn-primary" href="agentoreddetails.html?id='+obj2+'" style="height: 30px;margin-top: 5px;color: #FFF;">查看详情</a>';

}

function jubuok(obj) {
    mui.post('/Order/updateOrderType',
        {
            id:obj,
            status:2
        },
        function(data){
            console.log(data);
            if (data.code){
                window.location.reload();
                mui.toast('资料提交成功！');
            }
        },'json'
    )
}


function insertFullnew(obj) {
    mui.post('/Order/insertFullnew',
        {
            id:obj
        },
        function(data){
            console.log(data);
            if (data.code){
                mui.toast('资料提交成功正在准备支付！');
                getwxkey(data.object);
                window.location.reload();
            }
        },'json'
    )
}